package com.sisyphus.controller;

import com.sisyphus.dto.LoginDto;
import com.sisyphus.dto.UserRegisterDto;
import com.sisyphus.result.Result;
import com.sisyphus.service.IUserService;
import com.sisyphus.vo.LoginVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author Sisyphus
 * @since 2025-06-23
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    IUserService userService;

    @GetMapping("/hello")
    public String hello(){
        return "Hello World";
    }

    @PostMapping("/register")
    public Result register(@RequestBody @Valid UserRegisterDto dto) {
        userService.register(dto);
        return Result.ok("ok");
    }

    @PostMapping("/login")
    public Result<LoginVo> login(@RequestBody LoginDto dto) {
        LoginVo loginVo = userService.login(dto);
        return Result.ok(loginVo);
    }

}
